﻿using BackOfficeApplication.Controlers;
using BackOfficeApplication.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BackOfficeApplication.Views
{
    public partial class ImageUi : Form
    {
        public ImageUi()
        {
            InitializeComponent();
        }

        public ImageUi(ImageCtrl ctrl, ArticleCtrl articleCtrl)
            : this()
        {
            this._ctrl = ctrl;
            _articleCtrl = articleCtrl;
            BindingUI();
        }

        public void BindingUI()
        {
            Model = new ImageModel();
            imageModelBindingSource.DataSource = Model;
        }
        private ArticleCtrl _articleCtrl;
        private ImageCtrl _ctrl;
        public ImageModel Model { get; set; }

        private void ResetClick(object sender, EventArgs e)
        {
            try
            {
                _ctrl.Reset();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "infomation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void AddClick(object sender, EventArgs e)
        {
            //Dispose();
            _articleCtrl.AddImage(new ImageDto
            {
                AltText = Model.AltText,
                Caption = Model.Capiton,
                Position = (short)Model.SelectedPosition.Value,
                Source = Model.Source
            });
            Close();
        }
    }
}
